/*
 * @Description: 编辑移交归档单弹窗
 * @Author: Rfan
 * @Date: 2022-05-12 16:06:57
 * @LastEditTime: 2023-01-30 17:25:26
 */

import { useEffect } from 'react';
import { Button, Form, Modal } from 'antd';
import type { FC } from 'react';
import TransferForm from './common/TransferForm';
import type { ICommonDialog } from '@/interfaces/global';

interface EditTransferFormProps extends ICommonDialog {
  data: any;
}

const EditTransferForm: FC<EditTransferFormProps> = (props) => {
  console.log('add transfer dialog', props.visible);
  const { visible, data, onClose } = props;
  const [form] = Form.useForm();

  useEffect(() => {
    if (visible) {
      //
    }
  }, [visible]);

  /**
   * @description: 关闭弹窗
   */
  const onCancel = () => {
    form.resetFields();
    onClose();
  };

  /**
   * @description 提交表单，触发onFinish方法
   */
  const submitFunc = () => {
    form.submit();
  };

  return (
    <Modal
      title="修改移交申请单"
      visible={visible}
      width={600}
      destroyOnClose
      onCancel={onCancel}
      footer={[
        <Button key="close" onClick={onCancel}>
          取消
        </Button>,
        <Button
          key="create"
          type="primary"
          onClick={() => {
            submitFunc();
          }}
        >
          保存
        </Button>
      ]}
    >
      <TransferForm
        form={form}
        data={data}
        visible={visible}
        closeDialog={() => {
          onCancel();
        }}
      />
    </Modal>
  );
};

export default EditTransferForm;
